﻿using System;

using SharpGeometry.Basic;

//TODO: Add comments.
//TODO: Add documentation tags.

namespace SharpGeometry.GeometryMath
{
    public static class VectorMath
    {
        public static float Length(this Vector2D p1)
        {
            return (float)Math.Sqrt(Math.Pow(p1.X, 2) + Math.Pow(p1.Y, 2));
        }

        public static float SqLength(this Vector2D p1)
        {
            return (float)(Math.Pow(p1.X, 2) + Math.Pow(p1.Y, 2));
        }

        public static float Distance(this Vector2D p1, Vector2D p2)
        {
            return (float)Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2));
        }

        public static float SqDistance(this Vector2D p1, Vector2D p2)
        {
            return (float)(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2));
        }

        public static float Dot(this Vector2D p1, Vector2D p2)
        {
            return (float)(p1.X * p2.X + p1.Y * p2.Y);
        }

        public static Vector2D Normalize(this Vector2D p1)
        {
            float length = p1.Length();

            return new Vector2D(p1.X / length, p1.Y / length);
        }

        public static float Length(this Vector3D p1)
        {
            return (float)Math.Sqrt(Math.Pow(p1.X, 2) + Math.Pow(p1.Z, 2) + Math.Pow(p1.Z, 2));
        }

        public static float SqLength(this Vector3D p1)
        {
            return (float)(Math.Pow(p1.X, 2) + Math.Pow(p1.Z, 2) + Math.Pow(p1.Z, 2));
        }

        public static float Distance(this Vector3D p1, Vector3D p2)
        {
            return (float)Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Z - p2.Z, 2) + Math.Pow(p1.Z - p2.Z, 2));
        }

        public static float SqDistance(this Vector3D p1, Vector3D p2)
        {
            return (float)(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Z - p2.Z, 2) + Math.Pow(p1.Z - p2.Z, 2));
        }

        public static float Dot(this Vector3D p1, Vector3D p2)
        {
            return (float)(p1.X * p2.X + p1.Y * p2.Y + p1.Z * p2.Z);
        }

        public static Vector3D Normalize(this Vector3D p1)
        {
            float length = p1.Length();

            return new Vector3D(p1.X / length, p1.Y / length, p1.Z / length);
        }
    }
}
